Imports System.Data
Imports System.Data.SqlClient
Imports Entidad

Public Class UsuarioDatos

    Function logueoSistema(ByVal usu As Usuario) As Usuario
        Dim usua As Usuario = Nothing
        Dim conex As New Conexion
        Dim coneccion As SqlConnection = conex.conectar()
        coneccion.Open()
        Try
            Dim query As String = "SELECT CIA, SUC_Codigo, USU_Codigo, USU_Descripcion, USU_Contrasenia, USU_LogPidion, USU_LogPC, " &
                                  "USU_Picking, USU_Recepcion, USU_Traslados, USU_RegCodBarra, BAN_Codigo, USU_FecBandeja, USU_Activo " &
                                  "FROM Usuario " &
                                  "WHERE CIA = '" & usu.CIA & "' AND SUC_Codigo = '" & usu.SUC_Codigo & "' AND USU_Codigo = '" & usu.USU_Codigo & "'"

            Dim adapter As New SqlDataAdapter(query, coneccion)
            Dim ds As New DataSet
            adapter.Fill(ds)

            If ds.Tables(0).Rows.Count <> 0 Then
                
                usua = New Usuario(ds.Tables(0).Rows(0)("CIA").ToString.Trim, ds.Tables(0).Rows(0)("SUC_Codigo").ToString.Trim, ds.Tables(0).Rows(0)("USU_Codigo").ToString.Trim, ds.Tables(0).Rows(0)("USU_Descripcion").ToString.Trim,
                                   ds.Tables(0).Rows(0)("USU_Contrasenia").ToString.Trim, ds.Tables(0).Rows(0)("USU_LogPidion").ToString.Trim, ds.Tables(0).Rows(0)("USU_LogPC").ToString.Trim, ds.Tables(0).Rows(0)("USU_Picking").ToString.Trim,
                                   ds.Tables(0).Rows(0)("USU_Recepcion").ToString.Trim, ds.Tables(0).Rows(0)("USU_Traslados").ToString.Trim, ds.Tables(0).Rows(0)("USU_RegCodBarra").ToString.Trim, ds.Tables(0).Rows(0)("BAN_Codigo").ToString.Trim,
                                   ds.Tables(0).Rows(0)("USU_FecBandeja").ToString.Trim, ds.Tables(0).Rows(0)("USU_Activo").ToString.Trim)
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            coneccion.Close()
        End Try

        Return usua
    End Function

End Class
